<?php

namespace C\mod{
    use C\lib\Db;
    use C\lib\Sql;
    class worker extends mod{

        protected static $__table_s = 'worker';
        protected static $__primary_s = 'id';

        /*
         * 获取10公里内的工人端工人信息
         */
        static public function scope($lat, $lng ,$workerId) {
            Db::connect();
            $sql = new Sql();
            $sql->select('*', static::$__table_s)->append(' WHERE sqrt((((' . ($lng + 0) . '-lng)*PI()*12656*cos(((' . ($lat + 0) . '+lat)/2)*PI()/180)/180)*((' . ($lng + 0) . '-lng)*PI()*12656*cos(((' . ($lat + 0) . '+lat)/2)*PI()/180)/180))+(((' . ($lat + 0) . '-lat)*PI()*12656/180)*((' . ($lat + 0) . '-lat)*PI()*12656/180)))<10 AND id !='.$workerId.'');

            if ($ps = Db::query($sql->sql)) {
                $list = [];
                while ($o = $ps->fetchObject(static::class))
                    $list[] = $o;
                return $list;
            } else
                return false;
        }


        //获取用户n公里内的快递员(取递员)
        /*
         * distance 几公里的距离
         */
        static public function scop($lat,$lng,$distance) {
            Db::connect();
            $sql = new Sql();
            $sql->select('*', static::$__table_s)->append(' WHERE sqrt((((' . ($lng + 0) . '-lng)*PI()*12656*cos(((' . ($lat + 0) . '+lat)/2)*PI()/180)/180)*((' . ($lng + 0) . '-lng)*PI()*12656*cos(((' . ($lat + 0) . '+lat)/2)*PI()/180)/180))+(((' . ($lat + 0) . '-lat)*PI()*12656/180)*((' . ($lat + 0) . '-lat)*PI()*12656/180)))<'.$distance);
            if ($ps = Db::query($sql->sql)) {
                $list = [];
                while ($o = $ps->fetchObject(static::class))
                    $list[] = $o;
                return $list;
            } else
                return false;
        }


    }

}

